package com.api.shopapi.mapper;


import com.api.shopapi.entity.Serve;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface ServeMapper {


    @Insert("insert into serve " +
            "(" +
            "ServeCode, " +
            "UserCode, " +
            "BusinessCode, " +
            "Address, " +
            "Name, " +
            "Gender, " +
            "IdCard, " +
            "Age, " +
            "Img, " +
            "Phone, " +
            "ServiceContent, " +
            "ServiceRegion, " +
            "ServiceType, " +
            "ServiceStatus, " +
            "PersonNum, " +
            "Qualification, " +
            "HealthCards" +
            ") " +
            "VALUES " +
            "(" +
            "#{serve.ServeCode} ," +
            "#{serve.UserCode} ," +
            "#{serve.BusinessCode} ," +
            "#{serve.Address} ," +
            "#{serve.Name} ," +
            "#{serve.Gender} ," +
            "#{serve.IdCard} ," +
            "#{serve.Age} ," +
            "#{serve.Img} ," +
            "#{serve.Phone} ," +
            "#{serve.ServiceContent}," +
            "#{serve.ServiceRegion} ," +
            "#{serve.ServiceType} ," +
            "#{serve.ServiceStatus} ," +
            "#{serve.PersonNum} ," +
            "#{serve.Qualification} ," +
            "#{serve.HealthCards}  " +
            ")")
    int insert(@Param("serve") Serve serve);





    @Update("update serve " +
            "set " +
            "BusinessCode=#{serve.BusinessCode} ," +
            "Address=#{serve.Address} ," +
            "Name=#{serve.Name} ," +
            "Gender=#{serve.Gender} ," +
            "IdCard=#{serve.IdCard} ," +
            "Age=#{serve.Age} ," +
            "Img=#{serve.Img} ," +
            "Phone=#{serve.Phone} ," +
            "ServiceContent=#{serve.ServiceContent} ," +
            "ServiceRegion=#{serve.ServiceRegion} ," +
            "ServiceType=#{serve.ServiceType} ," +
            "ServiceStatus=#{serve.ServiceStatus} ," +
            "PersonNum=#{serve.PersonNum} ," +
            "Qualification=#{serve.Qualification} ," +
            "HealthCards=#{serve.HealthCards} " +
            "where " +
            "ServeCode=#{serve.ServeCode} ")
    int update(@Param("serve") Serve serve);


    @Select("<script>" +
            "select * from serve " +
            "where BusinessCode=#{businessCode} " +
            "<if test =' serviceStatus !=-1 '> " +
            " and  ServiceStatus = #{serviceStatus} " +
            "</if>" +
            "<if test ='name !=\"\" '>" +
            " and Name like concat('%',#{name},'%')" +
            "</if>" +
            "</script>")
    List<Serve> getPageList(@Param("name") String name,@Param("serviceStatus") int serviceStatus,
                            @Param("businessCode") String businessCode);






    @Delete("delete from serve where serveCode=#{serveCode}")
    int deleteByServeCode(@Param("serveCode") String serveCode);


    @Update("update serve set " +
            "BusinessCode=#{serve.BusinessCode}," +
            "Address=#{serve.Address}" +
            " where  ServeCode=#{serve.ServeCode}")
    int updateByServeCode(@Param("serve") Serve serve);


    @Select("select * from serve where serveCode=#{serveCode} limit 1")
    Serve getByServeCode(@Param("serveCode") String serveCode);

    @Select("select * from serve where userCode=#{userCode} limit 1")
    Serve getByUserCode(@Param("userCode") String userCode);


    @Select("select * from serve")
    List<Serve> getList();

    @Select("select * from serve where businessCode=#{businessCode} ")
    List<Serve> getListByBusinessCode(@Param("businessCode") String businessCode);


    //获取社区绑定的所有服务人员
    @Select("select s.* from serve s " +
            " join serve_zone_rel szr " +
            " on s.ServeCode = szr.ServeCode " +
            " where szr.zoneCode=#{zoneCode} ")
    List<Serve> getListByZoneCode(@Param("zoneCode") String zoneCode);



}
